home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume17 / contest-prog / part03 < prev    next >
Encoding:
Internet Message Format  |  1989-02-06  |  21.2 KB

  1. Subject:  v17i086:  ACM-style programmning contest programs, Part03/03
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: jim nelson <nelson@uncecs.edu>
  6. Posting-number: Volume 17, Issue 86
  7. Archive-name: contest-prog/part03
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line, then unpack
  11. # it by saving it into a file and typing "sh file".  To overwrite existing
  12. # files, type "sh file -c".  You can also feed this as standard input via
  13. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  14. # will see the following message at the end:
  15. #        "End of archive 3 (of 3)."
  16. # Contents:  contestrules gr prob18.c prob18.txt score.c
  17. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  18. if test -f 'contestrules' -a "${1}" != "-c" ; then 
  19.   echo shar: Will not clobber existing file \"'contestrules'\"
  20. else
  21. echo shar: Extracting \"'contestrules'\" \(3260 characters\)
  22. sed "s/^X//" >'contestrules' <<'END_OF_FILE'
  23. X
  24. XRules:
  25. X
  26. X1) The winning team in each category is the one which solves the most
  27. Xproblems in its appropriate category.  Period!
  28. X
  29. XHOWEVER:
  30. X
  31. X2) In the event of TIES, the penalty-point method will be used.  Teams
  32. Xwith fewer penalty points rank ahead of teams with more penalty points,
  33. Xfor the purpose of breaking ties only.
  34. X
  35. XPenalty points are assessed as follows:  
  36. X
  37. X    10 points for each incorrect judged run
  38. X
  39. X    1 point for every minute a problem (in your category) remains 
  40. X    unsolved by your team
  41. X
  42. X
  43. X3) You may make, without penalty, any number of trial runs of your
  44. Xprogram against your own input data, but a judged run is made against
  45. Xthe judges' input data, which you will NEVER (until after the end of
  46. Xthe contest) be allowed to see.
  47. X
  48. X4) The judging program will compile your program and run it against the
  49. Xjudges' input data, in a protected account.  You will be notified of
  50. Xthe correctness or incorrectness of your output by a program which
  51. Xcompares byte-by-byte your output with the correct answer ("diff").
  52. XThat's all.  You must read standard-input, and write standard-output.
  53. XYou may not open any additional file-descriptors or FILE *'s.
  54. X
  55. X5) Programs must be in C, Pascal, or Fortran.  They must be a single
  56. Xmonolithic file (you may #include).  We cannot handle makefiles, awk 
  57. Xscripts, compile-line options, etc.  Just plain & simple quick & dirty 
  58. Xcoding.  The judges will not look at the code, only the output.
  59. X
  60. X6) Your submitted source code must be named 
  61. X<something><problem#>.[c|f|p|pas]
  62. XIf your filename ends in .pas, the pascal  compiler will be invoked.
  63. XIf your filename ends in .p  , the pc      compiler will be invoked.
  64. XIf your filename ends in .f  , the fortran compiler will be invoked.
  65. XIf your filename ends in .c  , the cc      compiler will be invoked.
  66. XThe first digit-string will be deemed to be the problem number you
  67. Xare submitting.
  68. X
  69. XTo submit a program for judging, use the judge command.
  70. XExamples:
  71. X$ judge prob1.c
  72. X$ judge prog3.f
  73. X$ judge contestprob13.pas
  74. X$ judge why_did_i_ever_get_myself_into_this_12.p
  75. XYou will be notified by mail of the result of your judged run. (Or
  76. Xyou could periodically run "score").
  77. X
  78. X7) If your judged run is correct, the cutoff time for penalty points
  79. Xfor that problem will be the time you SUBMITTED it, NOT the time it
  80. Xwas judged; so don't be overly concerned that judging may take a few
  81. Xminutes.  Go work on another problem while waiting.
  82. X
  83. X8) As soon as the contest begins, you may find the statements of the
  84. Xproblems in the /tmp directory.  They will be named /tmp/probxx.txt,
  85. Xwhere xx is the number of the problem.  Beginners will be interested
  86. Xin prob1.txt up through prob6.txt.  Intermediates will be interested
  87. Xin prob7.txt up through prob12.txt.  Advanced entrants should
  88. Xhave already figured out that they want prob13.txt thru prob18.txt.
  89. X(It will do you no good to solve a problem in a category not
  90. Xappropriate to your class; the scoreboard program will ignore
  91. Xit, and you will have wasted your time.)
  92. X
  93. X9) Only one contestant per team may be logged in at any one time.
  94. X
  95. X10) The contest ends exactly four hours after it begins.  Problems
  96. Xsubmitted for judging after the cutoff time will not be judged.
  97. XHowever, juding of problems submitted just before the end may
  98. Xextend until all have been judged.
  99. END_OF_FILE
  100. if test 3260 -ne `wc -c <'contestrules'`; then
  101.     echo shar: \"'contestrules'\" unpacked with wrong size!
  102. fi
  103. # end of 'contestrules'
  104. fi
  105. if test -f 'gr' -a "${1}" != "-c" ; then 
  106.   echo shar: Will not clobber existing file \"'gr'\"
  107. else
  108. echo shar: Extracting \"'gr'\" \(3885 characters\)
  109. sed "s/^X//" >'gr' <<'END_OF_FILE'
  110. X#! /bin/sh
  111. Xcd $HOME
  112. Xif test -f lock
  113. Xthen
  114. X   echo another judge has me busy, try again momentarily
  115. X   exit
  116. Xfi
  117. Xfailure=""
  118. Xtouch lock
  119. Xcat $MAIL >>mal
  120. Xcp /dev/null $MAIL
  121. Xfn=`grep Judge:  mal |head -1`
  122. Xcase $fn in
  123. X   "")rm lock;exit;;
  124. Xesac
  125. Xfun=` echo $fn | sed 's/Judge/judge/'  `
  126. Xecho $fn
  127. Xecho $fun
  128. Xsed "s=$fn=$fun=" mal >/tmp/pqr$$
  129. Xcp /tmp/pqr$$ mal
  130. Xrm -f /tmp/pqr$$
  131. X
  132. X
  133. Xecho fn = $fn
  134. Xfl=`echo $fn|cut -f2 -d' '`
  135. Xecho fl = $fl
  136. Xseconds=`echo $fn|cut -f3 -d' '`
  137. Xecho seconds = $seconds
  138. Xendtime=`cat endtime`
  139. Xecho endtime = $endtime
  140. X
  141. Xda=`echo $fn|cut -f2 -d';'`
  142. Xecho da = $da
  143. X
  144. Xcase $fl in
  145. X   "")rm -f lock;exit;;
  146. Xesac
  147. X
  148. Xt=`echo $fl|cut -f3 -d'/'`
  149. Xecho t = $t
  150. Xcase $t in
  151. X   team0) t=judges;;
  152. Xesac
  153. Xecho t = $t
  154. Xp=`echo $fl|cut -f4 -d'/'`
  155. Xecho $seconds $endtime
  156. Xif expr $seconds '>' $endtime
  157. Xthen
  158. X   echo too late
  159. X   echo $fn >/tmp/dumb$$
  160. X   echo "submitted too late">>/tmp/dumb$$
  161. X   mail $t < /tmp/dumb$$
  162. X   rm /tmp/dumb$$
  163. X   rm lock
  164. X   exit
  165. Xelse
  166. X   echo not too late
  167. Xfi
  168. X
  169. Xsrc=`shorten $t.$p`
  170. Xecho src=$src
  171. Xecho p = $p
  172. Xif test -f $src.right
  173. Xthen
  174. X   echo They seem to have already completed that problem...
  175. X   echo  Do you want to proceed?
  176. X   read zork
  177. X   case $zork in
  178. X      y) ;;
  179. X      *) rm -f lock;exit;;
  180. X   esac
  181. Xfi
  182. X
  183. X
  184. X
  185. Xs=$fl
  186. Xecho s = $s
  187. Xext=`basename $s`
  188. Xecho ext = $ext
  189. Xcase $ext in
  190. X   *.p)c=pc;dot=p;;
  191. X   *.pas)c=pascal;dot=p;;
  192. X   *.c)c=cc;dot=c;;
  193. X   *.f)c=fortran;dot=f;;
  194. X   *) echo invalid extension;rm -f lock;exit;;
  195. Xesac
  196. X
  197. Xif test -f $s 
  198. Xthen
  199. X   echo cp $s $src.$$.$dot
  200. X   cp $s $src.$$.$dot
  201. Xelse
  202. X   echo $s not found
  203. X   echo $s >/tmp/dumb$$
  204. X   echo "was not found in your directory">>/tmp/dumb$$
  205. X   mail $t </tmp/dumb$$ 
  206. X   rm -f lock
  207. X   echo bye
  208. X   rm -f /tmp/dumb$$
  209. X   exit
  210. Xfi
  211. X#q=`echo $p|cut -f2 -db`
  212. X#q=`echo $q|cut -f1 -d.`
  213. Xq=`digits $p`
  214. Xqq=`digits $t`
  215. Xcase $q in
  216. X   -)q=99;;
  217. Xesac
  218. Xcase $qq in
  219. X   -)qq=99;;
  220. Xesac
  221. Xecho $qq $q
  222. Xecho $src.$$.$dot
  223. Xecho the compiler is $c
  224. Xif $c -o subdir/${src}.$$.e $src.$$.$dot
  225. Xthen
  226. X   echo compiled ok ... about to run it
  227. Xelse
  228. X   echo compilation failed
  229. X   failure=1
  230. Xfi
  231. Xcase $failure in
  232. X   "")
  233. X   echo about to run $src.$$.e
  234. X   cp prob$q.in subdir/prob$q.in$$
  235. X   echo cp prob$q.in subdir/prob$q.in$$
  236. X   #cd subdir
  237. X   if test -f prob$q.in
  238. X   then
  239. X      echo "chexec8 <subdir/prob$q.in$$ >out subdir/$src.$$.e"
  240. X      rm -f out
  241. X      chexec8 <subdir/prob$q.in$$ >out subdir/$src.$$.e
  242. X      chmod og-rwx out
  243. X      
  244. X   else
  245. X      echo prob$q.in$$ not found in gr ... you dummy!
  246. X      exit
  247. X   fi
  248. X   #cd ..
  249. X   echo through running
  250. X   diff  out  prob$q.ans
  251. X   rm -f subdir/*
  252. X   if compare out prob$q.ans
  253. X   then
  254. X      echo "1" $qq $q $seconds>>scoreboard
  255. X      echo yes their output is correct
  256. X      mv out keep/$src.$$.m
  257. X      rm lock
  258. X      echo \
  259. X      "CONGRATS! $t successfully did prob$q at `date`">\
  260. X      $src.right
  261. X      mail $t < $src.right
  262. X      echo "submitted: $seconds">$src.at
  263. X      echo "$t completed problem $q at `date`">$src.msg
  264. X      list=""
  265. X      for i in `cat listofteams` ; 
  266. X      do
  267. X         case $i in
  268. X            $t) ;;
  269. X            *) list="$list $i"
  270. X            ;;
  271. X         esac
  272. X      done
  273. X      mail $list < $src.msg
  274. X      exit
  275. X   else
  276. X      echo "0" $qq $q $seconds >>scoreboard
  277. X      echo not correct
  278. X      mv  out keep/$src.$$.m
  279. X      rm lock
  280. X      echo  "do you wish to mail them an explanatory note? "
  281. X      read zork
  282. X      case $zork in
  283. X         y) 
  284. X         echo "mail $t"
  285. X         mail -s "$p" $t
  286. X         ;;
  287. X         *) echo "your $p not correct">failure$$
  288. X         mail -s "$p" $t<failure$$
  289. X         rm -f failure$$
  290. X         ;;
  291. X      esac
  292. X   fi
  293. X   ;;
  294. X   1)
  295. X   echo "0" $qq $q $seconds >>scoreboard
  296. X   echo not correct
  297. X   mv out keep/$src.$$.m
  298. X   rm lock
  299. X   echo  "do you wish to mail them an explanatory note? "
  300. X   read zork
  301. X   case $zork in
  302. X      y) 
  303. X      echo "mail $t"
  304. X      mail -s "$p" $t
  305. X      ;;
  306. X      *) echo "your $p not correct">failure$$
  307. X      mail -s "$p" $t<failure$$
  308. X      rm -f failure$$
  309. X      ;;
  310. X   esac
  311. Xesac
  312. END_OF_FILE
  313. if test 3885 -ne `wc -c <'gr'`; then
  314.     echo shar: \"'gr'\" unpacked with wrong size!
  315. fi
  316. chmod +x 'gr'
  317. # end of 'gr'
  318. fi
  319. if test -f 'prob18.c' -a "${1}" != "-c" ; then 
  320.   echo shar: Will not clobber existing file \"'prob18.c'\"
  321. else
  322. echo shar: Extracting \"'prob18.c'\" \(5065 characters\)
  323. sed "s/^X//" >'prob18.c' <<'END_OF_FILE'
  324. X/*
  325. XProblem 18:Expanding square codes
  326. X
  327. X   One method of encoding messages is known as the "expanding square
  328. Xcode."  This method encodes messages by placing the characters of the 
  329. Xmessage to be encoded in an odd order(1,3,5,7,9) square matrix row by 
  330. Xrow, and then retrieves them (decoding) in a clockwise expanding
  331. Xsquare spiral from the center of the matrix.  If the message is not
  332. Xexactly the right length to fill the matrix, the rest of the matrix
  333. Xis filled with asterisk characters (*).
  334. X
  335. X   For example, the two square matrices below show the order in which
  336. Xthe characters are placed in a matrix(order 5), and the order in which
  337. Xthey are to be retrieved.  Notice that the order of retrieval begins
  338. Xat the center, then proceeds to the right, and then spirals
  339. Xclockwise.
  340. X
  341. X      order in                       order out
  342. X
  343. X      1   2   3   4   5               21  22  23  24  25
  344. X      6   7   8   9  10               20   7   8   9  10
  345. X     11  12  13  14  15               19   6   1   2  11
  346. X     16  17  18  19  20               18   5   4   3  12
  347. X     21  22  23  24  25               17  16  15  14  13
  348. X
  349. X Examples:
  350. X
  351. X   encode:
  352. X     message in:  "This is a test message!"
  353. X
  354. X     message out: "stssees a  a**!egmtiThis "     
  355. X
  356. X   decode:
  357. X     message in:  "anreh is io *.enotshAnd t"
  358. X
  359. X     message out: "And this is another one."
  360. X
  361. X   Your program should be able to encode and to decode messages by 
  362. Xthis method.  The input will consist of pairs of lines; the first 
  363. Xline in each pair will contain either the word   encode   or the word
  364. Xdecode   in lower case characters.  The second line in each pair will
  365. Xconsist of a message to be either encoded or decoded by the above 
  366. Xmethod, containing a maximum of 80 characters.  There will be no
  367. Xquotation marks (") surrounding the messages, and you should not
  368. Xoutput your messages with "'s.
  369. X
  370. X   From the length of the message, you should determine the minimum
  371. Xodd order required for the matrix, and perform the specified operation.
  372. XThe output for each operation will consist of one blank line, the
  373. Xgiven message, and the resultant message.  Each message should be
  374. Xon a separate line. A decoded message may not contain the asterisk 
  375. Xcharacters used to fill the matrix in the encoding process.  You 
  376. Xmay assume that no actual message contains an asterisk.
  377. X
  378. X   Your program should continue reading input lines and performing
  379. Xoperations until something other than the words   encode  or
  380. Xdecode  is encountered.
  381. X
  382. XHere is an actual run; the input file consisted of exactly four lines.
  383. XThe output file consists of exactly six lines; lines 1 and 4 are
  384. Xblank lines.
  385. XThis was the input file (the next four lines):
  386. Xencode
  387. Xnow is the time for all
  388. Xdecode
  389. Ximroft thee **lla  snow i
  390. XHere was the output file (the next six lines, NOTICE the blank lines!):
  391. X
  392. Xnow is the time for all
  393. Ximroft thee **lla  snow i
  394. X
  395. Ximroft thee **lla  snow i
  396. Xnow is the time for all
  397. X*/
  398. X#include <stdio.h>
  399. X#include <kindex.c>
  400. X#define newline '\n'
  401. X#define null '\0'
  402. Xint E[]={0,1};
  403. Xint S[]={1,0};
  404. Xint W[]={0,-1};
  405. Xint N[]={-1,0};
  406. Xint *dir;
  407. Xint x,y;
  408. Xint size;
  409. X#define SZ 55
  410. Xint a[SZ+3][SZ+3];
  411. X
  412. Xmain(){
  413. X    int len,d,n,i,k,j,jj;
  414. X    char line[256];
  415. X
  416. X    while( gets(line)==line){
  417. X    if(kindex(line,"encode")==0)goto encode;
  418. X    if(kindex(line,"decode")==0)goto decode;
  419. X    exit(0);
  420. X    encode:
  421. X    putchar(newline);
  422. X    gets(line);
  423. X    puts(line);
  424. X    for(i=0;i<=90;i++)if(line[i]==newline ||line[i]==null)break;
  425. X    line[i]=null;
  426. X    len=i;
  427. X    for(size=1;;size++,size++)if(size*size>=len)break;
  428. X    for(i=len;i<size*size;i++)line[i]='*';line[i]=null;
  429. Xfor(i=1;i<=SZ;i++)for(k=1;k<=SZ;k++){a[i][k]= 0;}
  430. Xj=0;
  431. Xfor(i=1;i<=size;i++)for(k=1;k<=size;k++){a[i][k]=line[j++];}
  432. X/*
  433. Xfor(i=1;i<=size;i++)
  434. X{
  435. X    for(k=1;k<=size;k++){
  436. X            printf("%c",a[i][k]);
  437. X    }
  438. X    putchar(newline);}
  439. X    */
  440. X    x=y=(size+1)/2;
  441. X    n=size*size;
  442. X    dir=E;
  443. X    printf("%c",a[x][y]);
  444. X    for(k=1;k<=size;k++){
  445. X        for(j=1;j<=k;j++){ 
  446. X        d=godir();if(d>0)printf("%c",d); if(d<0)goto out;
  447. X        }
  448. X        nextdir();
  449. X        for(j=1;j<=k;j++){
  450. X        d=godir();if(d>0)printf("%c",d); if(d<0)goto out;
  451. X        }
  452. X        nextdir();
  453. X    }
  454. X    out:putchar(newline);
  455. X    goto getnextline; 
  456. X
  457. X    decode:
  458. X    /*for(i=0;i<=SZ;i++)for(j=0;j<=SZ;j++)a[i][j]=1;*/
  459. X    putchar(newline);
  460. X    gets(line);
  461. X    for(i=0;i<=90;i++)if(line[i]==newline ||line[i]==null)break;
  462. X    line[i]=null;
  463. X    puts(line);
  464. X    len=i;
  465. X    for(size=1;;size++,size++)if(size*size>=len)break;
  466. X    for(i=len;i<size*size;i++)line[i]=' ';line[i]=null;
  467. X    x=y=(size+1)/2;
  468. X    n=size*size;
  469. X    dir=E;
  470. X    jj=0;
  471. X    a[x][y]=line[jj++];
  472. X    for(k=1;k<=size;k++){
  473. X        for(j=1;j<=k;j++){ 
  474. X        d=godir();a[x][y]=line[jj++]; if(jj>n)goto out1;
  475. X/*        printf("x,y= %d %d\n",x,y);*/
  476. X        }
  477. X        nextdir();
  478. X        for(j=1;j<=k;j++){
  479. X        d=godir();a[x][y]=line[jj++]; if(jj>n)goto out1;
  480. X/*        printf("x,y= %d %d\n",x,y);*/
  481. X        }
  482. X        nextdir();
  483. X    }
  484. X    out1:
  485. X    jj=0;
  486. X    for(i=1;i<=size;i++)for(j=1;j<=size;j++)line[jj++]=a[i][j];
  487. X    for(i=0;i<100;i++)if(line[i]=='*')line[i]=null;
  488. X    puts(line);
  489. Xgetnextline: ;
  490. X}
  491. X}
  492. Xgodir()
  493. X{
  494. X    x= x+ dir[0];
  495. X    y= y+ dir[1];
  496. X    if(y<1 || y>size)return -1;
  497. X    if(x<1 || x>size)return -1;
  498. X    return a[x][y];
  499. X
  500. X}
  501. Xnextdir()
  502. X{
  503. X    if(dir==E){dir=S;return;}
  504. X    if(dir==S){dir=W;return;}
  505. X    if(dir==W){dir=N;return;}
  506. X    if(dir==N){dir=E;return;}
  507. X
  508. X}
  509. END_OF_FILE
  510. if test 5065 -ne `wc -c <'prob18.c'`; then
  511.     echo shar: \"'prob18.c'\" unpacked with wrong size!
  512. fi
  513. # end of 'prob18.c'
  514. fi
  515. if test -f 'prob18.txt' -a "${1}" != "-c" ; then 
  516.   echo shar: Will not clobber existing file \"'prob18.txt'\"
  517. else
  518. echo shar: Extracting \"'prob18.txt'\" \(3113 characters\)
  519. sed "s/^X//" >'prob18.txt' <<'END_OF_FILE'
  520. XProblem 18: Expanding square codes.
  521. X
  522. X   One method of encoding messages is known as the "expanding square
  523. Xcode."  This method encodes messages by placing the characters of the 
  524. Xmessage to be encoded in an odd order(1,3,5,7,9) square matrix row by 
  525. Xrow, and then retrieves them (decoding) in a clockwise expanding
  526. Xsquare spiral from the center of the matrix.  If the message is not
  527. Xexactly the right length to fill the matrix, the rest of the matrix
  528. Xis filled with asterisk characters (*).
  529. X
  530. X   For example, the two square matrices below show the order in which
  531. Xthe characters are placed in a matrix(order 5), and the order in which
  532. Xthey are to be retrieved.  Notice that the order of retrieval begins
  533. Xat the center, then proceeds to the right, and then spirals
  534. Xclockwise.
  535. X
  536. X      order in                       order out
  537. X
  538. X      1   2   3   4   5               21  22  23  24  25
  539. X      6   7   8   9  10               20   7   8   9  10
  540. X     11  12  13  14  15               19   6   1   2  11
  541. X     16  17  18  19  20               18   5   4   3  12
  542. X     21  22  23  24  25               17  16  15  14  13
  543. X
  544. X Examples:
  545. X
  546. X   encode:
  547. X     message in:  "This is a test message!"
  548. X
  549. X     message out: "stssees a  a**!egmtiThis "     
  550. X
  551. X   decode:
  552. X     message in:  "anreh is io *.enotshAnd t"
  553. X
  554. X     message out: "And this is another one."
  555. X
  556. X   Your program should be able to encode and to decode messages by 
  557. Xthis method.  The input will consist of pairs of lines; the first 
  558. Xline in each pair will contain either the word   encode   or the word
  559. Xdecode   in lower case characters.  The second line in each pair will
  560. Xconsist of a message to be either encoded or decoded by the above 
  561. Xmethod, containing a maximum of 80 characters.  There will be no
  562. Xquotation marks (") surrounding the messages, and you should not
  563. Xoutput your messages with "'s.
  564. X
  565. X   From the length of the message, you should determine the minimum
  566. Xodd order required for the matrix, and perform the specified operation.
  567. XThe output for each operation will consist of one blank line, the
  568. Xgiven message, and the resultant message.  Each message should be
  569. Xon a separate line. A decoded message may not contain the asterisk 
  570. Xcharacters used to fill the matrix in the encoding process.  You 
  571. Xmay assume that no actual message contains an asterisk.
  572. X
  573. X   You may assume that no input line will be longer than 80 characters,
  574. Xso that a matrix larger than 9x9 will never be required.
  575. X
  576. X   Your program should continue reading input lines and performing
  577. Xoperations until something other than the words   encode  or
  578. Xdecode  is encountered.
  579. X
  580. X   By the way, this is a TERRIBLE code; try it on a "quick brown fox"
  581. Xand see if you can't guess it.
  582. X
  583. XHere is an actual run; the input file consisted of exactly four lines.
  584. XThe output file consists of exactly six lines; lines 1 and 4 are
  585. Xblank lines.
  586. XThis was the input file (the next four lines):
  587. Xencode
  588. Xnow is the time for all
  589. Xdecode
  590. Ximroft thee **lla  snow i
  591. XHere was the output file (the next six lines, NOTICE the blank lines!):
  592. X
  593. Xnow is the time for all
  594. Ximroft thee **lla  snow i
  595. X
  596. Ximroft thee **lla  snow i
  597. Xnow is the time for all
  598. END_OF_FILE
  599. if test 3113 -ne `wc -c <'prob18.txt'`; then
  600.     echo shar: \"'prob18.txt'\" unpacked with wrong size!
  601. fi
  602. # end of 'prob18.txt'
  603. fi
  604. if test -f 'score.c' -a "${1}" != "-c" ; then 
  605.   echo shar: Will not clobber existing file \"'score.c'\"
  606. else
  607. echo shar: Extracting \"'score.c'\" \(2852 characters\)
  608. sed "s/^X//" >'score.c' <<'END_OF_FILE'
  609. X#define CURVERS 21
  610. X#define HOURS 4
  611. X#include <stdio.h>
  612. X#include <sys/types.h>
  613. X#ifdef sequent
  614. X#include <sys/time.h>
  615. X#else
  616. X#include <time.h>
  617. X#endif
  618. Xint prob,team;
  619. Xchar *let[4] = {
  620. X    "   ","beg","int","adv"};
  621. Xint category[31];
  622. X
  623. Xmain()
  624. X{
  625. X    char *malloc();
  626. X    char *end;
  627. X    FILE *fopen(), *fp ;
  628. X    int sus,finish;
  629. X    long version,starttime;
  630. X    char *teamnames[31], *strcpy();
  631. X    time_t ct,ct1;
  632. X    long time();
  633. X    int solvedat[31][19];
  634. X    int penal[31],nfail[31],nworked[31];
  635. X    int i,k;
  636. X    long  endcontest;
  637. X    char temp[81];
  638. X
  639. X    for(team=1;team<=30;team++){
  640. X        penal[team]=0;
  641. X        nfail[team]=0;
  642. X        nworked[team]=0;
  643. X        teamnames[team]=(char *)0;
  644. X        for(prob=1;prob<=18;prob++)solvedat[team][prob]=0;
  645. X    }
  646. X
  647. X    if ((fp= fopen(SCOREBOARD,"r")) == NULL) {
  648. X        printf("Can not open scoreboard file [%s].\n",SCOREBOARD);
  649. X        exit(1);
  650. X    } 
  651. X
  652. X    if ( fscanf(fp,"%d",&version) != 1) {
  653. X        printf("Can not read version from scoreboard\n");
  654. X        exit(2);
  655. X    }
  656. X    if (version!=CURVERS){
  657. X        puts("an old version perhaps?");
  658. X        exit(8);
  659. X    }
  660. X    for(i=1;i<=30;i++){
  661. X        if( fscanf(fp,"%d%d%s",&team,&k,temp) != 3){
  662. X            printf("%d%d%s\n",team,k,temp);exit(3);}
  663. X            if(team==99)team=0;
  664. X        if(k<0){
  665. X        break;
  666. X        }
  667. X        else {
  668. X        if(team==99)team=0;
  669. X        category[team]=k;
  670. X        teamnames[team]=malloc((unsigned)(strlen(temp)+2));
  671. X        (void)strcpy(teamnames[team],temp);
  672. X        }
  673. X    }
  674. X
  675. X    if(1!=fscanf(fp,"%ld",&starttime))exit(5) ;
  676. X    endcontest=starttime+HOURS*3600;
  677. X    ct = time((long *)0);
  678. X    ct1=ct;
  679. X    end="ends ";
  680. X    if(ct>endcontest){ct=endcontest;end="ended";}
  681. X
  682. X    while ( fscanf(fp,"%d %d %d %d",&sus,&team,&prob,&finish) == 4) {
  683. X        if(team==99)team=0;
  684. X        if (sus) { 
  685. X            solvedat[team][prob]=finish;
  686. X        }
  687. X        else{
  688. X            nfail[team]++;
  689. X            penal[team] += 10;
  690. X        }
  691. X    }/*end of file*/
  692. X
  693. X    (void) fclose(fp);
  694. X
  695. X    for(team=1;team<=30;team++)
  696. X        if(category[team])
  697. X            for(k=prob=category[team]*6-5;prob<k+6;prob++)
  698. X                if(solvedat[team][prob])
  699. X                {
  700. X                    penal[team] +=(solvedat[team][prob]-starttime)/60;
  701. X                    nworked[team]++;
  702. X                }
  703. X                else
  704. X                {
  705. X        penal[team] += (ct  - starttime)/60;
  706. X                }
  707. X
  708. X    printf("\n                    the scoreboard \n\n");
  709. X    printf("                %s\n",ctime((time_t *)&ct1));
  710. X    printf("        contest began %s",ctime( (time_t *) &starttime));
  711. X    printf("        contest %s %s\n",end,ctime( (time_t *) &endcontest));
  712. X    printf(
  713. X    "team class  #fail   penal  #solved   which           who\n");
  714. X    for(i=3;i>=1;i--)
  715. X    /*if(i!=2)*//*this line eliminates the intermediate category*/
  716. X    {
  717. X        puts("");
  718. X        for(team=1;team<=15;team++)
  719. X            if(category[team]==i)
  720. X            {
  721. X                printf("%3d  %s %5d%11d     %d  "
  722. X                    ,team,let[category[team]],nfail[team],
  723. X                penal[team],
  724. X                nworked[team]);
  725. X                if(category[team])
  726. X                    for(k=prob=category[team]*6-5;prob<k+6;prob++)
  727. X                        if(solvedat[team][prob])printf("%3d", prob);
  728. X                        else printf("  .");
  729. X                if(teamnames[team]){
  730. X                    (void)putchar(' ');
  731. X                    (void)putchar(' ');
  732. X                    puts(teamnames[team]);
  733. X                }
  734. X                else printf("\n");
  735. X            }
  736. X    }
  737. X
  738. X}
  739. END_OF_FILE
  740. if test 2852 -ne `wc -c <'score.c'`; then
  741.     echo shar: \"'score.c'\" unpacked with wrong size!
  742. fi
  743. # end of 'score.c'
  744. fi
  745. echo shar: End of archive 3 \(of 3\).
  746. cp /dev/null ark3isdone
  747. MISSING=""
  748. for I in 1 2 3 ; do
  749.     if test ! -f ark${I}isdone ; then
  750.     MISSING="${MISSING} ${I}"
  751.     fi
  752. done
  753. if test "${MISSING}" = "" ; then
  754.     echo You have unpacked all 3 archives.
  755.     rm -f ark[1-9]isdone
  756. else
  757.     echo You still need to unpack the following archives:
  758.     echo "        " ${MISSING}
  759. fi
  760. ##  End of shell archive.
  761. exit 0
  762.  
  763.